package com.neusoft.demo6;

import java.util.Scanner;

public class TestEmployee {
    /**
     * 定义方法：添加员工
     * @param args
     */

    /**
     * 查询所有员工信息
     * @param args
     */

    public static void main(String[] args) {
        //从控制台录入3次员工信息,并将这些信息保存到员工对象中
        //要将这些员工保存到一个数组中
        //遍历数组获取所有员工的信息
        //1. 创建Scanner对象并接收用户输入的员工信息
        Scanner input = new Scanner(System.in);
        Employee[] employees = new Employee[3];
        for (int i = 0;i<3;i++) {
            System.out.println("请输入员工的编号：");
            int eid = input.nextInt();
            System.out.println("请输入员工的姓名：");
            String name = input.next();
            System.out.println("请输入员工的性别：");
            String sex = input.next();
            System.out.println("请输入员工的部门：");
            String department = input.next();
            System.out.println("请输入员工的工资：");
            double salary = input.nextDouble();
            //2. 创建一个员工对象并调用set方法，将获取到的员工的信息通过set方法给属性赋值
            Employee employee = new Employee();
            employee.setEid(eid);
            employee.setName(name);
            employee.setSex(sex);
            employee.setDepartment(department);
            employee.setSalary(salary);
            //3. 将员工对象保存到数组中
            employees[i] = employee;
        }
        //4. 遍历employees数组，获取所有员工信息
        for (int i = 0;i<employees.length;i++) {
            Employee e = employees[i];
            System.out.println(e.getEid() + " " + e.getName() + " " + e.getSalary());
        }
//        for (Employee employee : employees) {
//            System.out.println(employee.getEid() + " " + employee.getName() + " " + employee.getSalary());
//        }



    }
}
